# Maintainer: Andrew Sun <adsun701@gmail.com>

_pyname=PyStemmer
_realname=pystemmer
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.2.0
pkgrel=1
pkgdesc="Snowball stemming algorithms, for information retrieval (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/snowballstem/pystemmer/"
license=('MIT' 'BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-libstemmer")
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz"
        001-allow-building-with-system-libstemmer.patch::https://github.com/snowballstem/pystemmer/commit/2f52b4b2.patch)
sha256sums=('e2171b91b86bb1c6a9dddf09e8c867e488f8bd69bde07d0410a35cdcee0d857c'
            'a4443a7fe6418aeb7859166a4c3bf8a90b78b3aedab1abf4b30477e153c882af')

prepare() {
  cd "${srcdir}"/${_pyname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-allow-building-with-system-libstemmer.patch

  rm -rf "${srcdir}"/python-build-${MSYSTEM} | true
  cp -r "${srcdir}"/"${_pyname}-${pkgver}" "${srcdir}"/"python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  PYSTEMMER_SYSTEM_LIBSTEMMER=1 ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  PYSTEMMER_SYSTEM_LIBSTEMMER=1 \
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
